package clientGui;

import javax.swing.*;

import client.Client;

import java.awt.*;
import java.awt.event.WindowEvent;

public class MainWindow extends JFrame
{
	private static final long serialVersionUID = -7813948785927753869L;
	private LoginPanel loginPanel;
	private ChatCard chatCard;
	
	public MainWindow()
	{
		super();
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		addWindowListener(new java.awt.event.WindowAdapter()
		{
		    public void windowClosing(WindowEvent winEvt)
		    {
		    	System.out.println("Close window request");
		        Client.stop();
		        System.exit(0); 
		    }
		});
		
		getContentPane().setLayout(new CardLayout(0, 0));
		
		loginPanel = new LoginPanel();
		getContentPane().add(loginPanel, "loginPanel");
		
		chatCard = new ChatCard();
		getContentPane().add(chatCard, "chatCard");
		
		setVisible(true);
		pack();
	}
	
	public void showChat()
	{
		CardLayout cl = (CardLayout) this.getContentPane().getLayout();
		cl.show(this.getContentPane(), "chatCard");
	}
	
	public ChatPanel getChatPanel()
	{
		return chatCard.getChatPanel();
	}

	public UsersPanel getUsersPanel()
	{
		return chatCard.getUsersPanel();
	}
}
